﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;

namespace QuickExcel
{
    public partial class DatePicker : Form
    {
        public DatePicker()
        {
            InitializeComponent();
        }

        private void cmdClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmdPutDate_Click(object sender, EventArgs e)
        {
            Excel.Range rng = Globals.ThisAddIn.Application.Selection;
            rng.Value2 = calDatePicker.SelectionStart.Date;

            if (comDateFormat.Text != "(no change)" && comDateFormat.Text != "(serial number)")
            {
                rng.NumberFormat = comDateFormat.Text.ToString();
            }
            else if (comDateFormat.Text == "(serial number)")
            {
                rng.NumberFormat = "General";
                rng.Value = rng.Value2;
            }
            this.Close();
        }

        private void cmdDateFormat_Click(object sender, EventArgs e)
        {
            Excel.Range rng = Globals.ThisAddIn.Application.Selection;

            if (comDateFormat.Text != "(serial number)" && comDateFormat.Text != "(no change)")
            {
                rng.NumberFormat = comDateFormat.Text.ToString();
            }
            else if (comDateFormat.Text == "(serial number)")
            {
                rng.NumberFormat = "General";
                rng.Value = rng.Value2;
            }
            this.Close();
        }
    }
}
